package game

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/game"
    gameReq "github.com/flipped-aurora/gin-vue-admin/server/model/game/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type GameServerApi struct {}

var gameServerService = service.ServiceGroupApp.GameServiceGroup.GameServerService


// CreateGameServer 创建gameServer表
// @Tags GameServer
// @Summary 创建gameServer表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameServer true "创建gameServer表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /gameServer/createGameServer [post]
func (gameServerApi *GameServerApi) CreateGameServer(c *gin.Context) {
	var gameServer game.GameServer
	err := c.ShouldBindJSON(&gameServer)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := gameServerService.CreateGameServer(&gameServer); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteGameServer 删除gameServer表
// @Tags GameServer
// @Summary 删除gameServer表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameServer true "删除gameServer表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /gameServer/deleteGameServer [delete]
func (gameServerApi *GameServerApi) DeleteGameServer(c *gin.Context) {
	ID := c.Query("ID")
	if err := gameServerService.DeleteGameServer(ID); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteGameServerByIds 批量删除gameServer表
// @Tags GameServer
// @Summary 批量删除gameServer表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /gameServer/deleteGameServerByIds [delete]
func (gameServerApi *GameServerApi) DeleteGameServerByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	if err := gameServerService.DeleteGameServerByIds(IDs); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateGameServer 更新gameServer表
// @Tags GameServer
// @Summary 更新gameServer表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body game.GameServer true "更新gameServer表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /gameServer/updateGameServer [put]
func (gameServerApi *GameServerApi) UpdateGameServer(c *gin.Context) {
	var gameServer game.GameServer
	err := c.ShouldBindJSON(&gameServer)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := gameServerService.UpdateGameServer(gameServer); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindGameServer 用id查询gameServer表
// @Tags GameServer
// @Summary 用id查询gameServer表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query game.GameServer true "用id查询gameServer表"
// @Success 200 {object} response.Response{data=object{regameServer=game.GameServer},msg=string} "查询成功"
// @Router /gameServer/findGameServer [get]
func (gameServerApi *GameServerApi) FindGameServer(c *gin.Context) {
	ID := c.Query("ID")
	if regameServer, err := gameServerService.GetGameServer(ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(regameServer, c)
	}
}

// GetGameServerList 分页获取gameServer表列表
// @Tags GameServer
// @Summary 分页获取gameServer表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query gameReq.GameServerSearch true "分页获取gameServer表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /gameServer/getGameServerList [get]
func (gameServerApi *GameServerApi) GetGameServerList(c *gin.Context) {
	var pageInfo gameReq.GameServerSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	if list, total, err := gameServerService.GetGameServerInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}

// GetGameServerPublic 不需要鉴权的gameServer表接口
// @Tags GameServer
// @Summary 不需要鉴权的gameServer表接口
// @accept application/json
// @Produce application/json
// @Param data query gameReq.GameServerSearch true "分页获取gameServer表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /gameServer/getGameServerPublic [get]
func (gameServerApi *GameServerApi) GetGameServerPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的gameServer表接口信息",
    }, "获取成功", c)
}
